//
//  Map.m
//  Nuevo Mundo
//
//  Created by Bob Rosset on 7/1/12.
//  Copyright 2012 __MyCompanyName__. All rights reserved.
//

#import "Map.h"

@implementation Map

static Map* instance;

+(Map*)sharedInstance
{
	@synchronized(self) {
		if (!instance)
			instance = [Map node];
		return instance;
	}
}

-(id) init
{
	self = [super initWithColor:ccc4(54,78,161,255)];
	if (self != nil) {
		/*** Global Settings ***/
		NSString *path = [[NSBundle mainBundle] pathForResource:@"GlobalSettings" ofType:@"plist"];
		NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
		squareSize = [[dict objectForKey:@"squareSize"] intValue];
		squaresPerWidth = [[dict objectForKey:@"SquaresPerWidth"] intValue];
		squaresPerHeight = [[dict objectForKey:@"SquaresPerHeight"] intValue];
		/*** Global Settings ***/
		
		self.isTouchEnabled = YES;
		self.contentSize = CGSizeMake(squareSize*squaresPerWidth, squareSize*squaresPerHeight);
		
		/*** debug only ***/		
		for(int row=0;row<squaresPerHeight;row++) {
			for(int col=0;col<squaresPerWidth;col++) {
				
				CCLayerColor* debugSquare;
				
				if((col+row)%2) {
					debugSquare	= [[[CCLayerColor alloc] initWithColor:ccc4(255, 0, 0, 255) width:squareSize height:squareSize] autorelease];
				} else {
					debugSquare	= [[[CCLayerColor alloc] initWithColor:ccc4(0, 255, 0, 255) width:squareSize height:squareSize] autorelease];
				}
				
				[self addChild:debugSquare];
				debugSquare.position = CGPointMake(col*squareSize, row*squareSize);
			}
		}
		/*** debug only ***/
	}
	
	return self;
}

@end
